package com.liao.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.liao.bean.Codes;
import com.liao.bean.result.Msg;
import com.liao.bean.result.PageResult;
import com.liao.dao.CodeDao;
import com.liao.service.CodeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CodeServiceImpl implements CodeService {

    @Autowired
    private CodeDao codeDao;


    @Override
    public PageResult<Codes> queryCodeListByPage(Integer currentPage, Integer pageSize, String fieldName) throws Exception {
        PageHelper.startPage(currentPage,pageSize);
        //查询所有菜单
        List<Codes> codesList = codeDao.selectCodeListLikeCodeName(fieldName);
        PageInfo<Codes> pageInfo = new PageInfo<>(codesList);
        return new PageResult<>(0, Msg.CODE_QUERY_SUCCESS,pageInfo.getTotal(),pageInfo.getList());
    }

    @Override
    public void addCode(Codes code) throws Exception {
        codeDao.addCode(code);
    }

    @Override
    public void editCode(Codes code) throws Exception {
        codeDao.updateCode(code);
    }

    @Override
    public void deleteCode(String codeId) throws Exception {
        codeDao.deleteCode(codeId);
    }
}
